#!/usr/bin/perl
#Programmer: Rory Carmichael
#Purpose: Transform sequence names in file to be orthomcl friendly
#Usage: rename_seqs.pl <file>

my $file = $ARGV[0];
chomp $file;
`mv $file $file.backup`;
my $prefix = [split(/\./, $file)]->[0];
open(IF, "$file.backup") or die("Couldn't open backup file\n");
open(OF, ">$file") or die("Couldn't open rewrite file\n");
open(LUT, ">$file.lut") or die("Couldn't access lut\n");
my $i = 0;
while(my $line = <IF>) {
	chomp $line;
	if ($line =~ />/) {
		print LUT "$line\t>$prefix|$i\n";
		print OF ">$prefix|$i\n";
		$i++;
	} else {
		print OF "$line\n";
	}
}
close(IF);
close(OF);
close(LUT);
